﻿app.controller('HomeController', ['$scope', 'MovieFactory', function ($scope, MovieFactory) {
    $scope.isAdding = false;
    $scope.addMovie = {};
    $scope.movies = MovieFactory.movies;

    $scope.createMovie = function () {
        MovieFactory.createMovie($scope.addMovie).then(function (data) {
            $scope.isAdding = false;
            $scope.addMovie = {};
            alert("Movie has been added");
        }, function (data) {
            alert(data)
        });
    };

    $scope.deleteMovie = function (id) {
        MovieFactory.deleteMovie(id).then(function (data) {
            alert("Movie has been deleted");
        }, function (data) {
            alert("Failed to delete movie.");
        });
    };
}]);